﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DHQGHN.DAL.Base;
using DHQGHN.DAL.Common;
using DHQGHN.DAL.DAO.Admin;
using DHQGHN.DAL.Models.Admin;

namespace DHQGHN.DAL.BO.Admin
{
    public class ServeyMethodBO : BaseBO
    {
        public const string FIELD_SURVEY_METHOD_ID = "SURVEY_METHOD_ID";
        public const string FIELD_CODE = "CODE";
        public const string FIELD_NAME = "NAME";
        public const string FIELD_DESCRIPTIONS = "DESCRIPTIONS";
        public const string FIELD_DELETED = "DELETED";
        public const string FIELD_RECORD_COUNT = "RecordCount";

        public ServeyMethodDAO _ServeyMethodDAO;
        private string _connectionString;

        public ServeyMethodBO()
        {
            this._connectionString = Common.ConnectionUtil.TKTHDS_METADATA_CONNECTION_STRING;
        }

        public DataPage<ServeyMethodModel> GetDynamicListPaging(ServeyMethodModel sModel, int pageSize, int pageIndex)
        {
            try
            {
                _ServeyMethodDAO = CreateSQLDAO();
                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
               {
                {ServeyMethodModel.FIELD_SURVEY_METHOD_ID,FIELD_SURVEY_METHOD_ID},
                {ServeyMethodModel.FIELD_CODE, FIELD_CODE},
                {ServeyMethodModel.FIELD_NAME, FIELD_NAME},
                {ServeyMethodModel.FIELD_DESCRIPTIONS, FIELD_DESCRIPTIONS},
                {ServeyMethodModel.FIELD_DELETED,FIELD_DELETED},
                {ServeyMethodModel.FIELD_RECORD_COUNT, FIELD_RECORD_COUNT},
               };

                return _ServeyMethodDAO.GetDynamicListPaging(sModel, pageSize, pageIndex, mapDictionary);

            }
            catch (Exception)
            {
                throw;
            }
        }

        private ServeyMethodDAO CreateSQLDAO()
        {
            return new ServeyMethodDAO(_connectionString, DEFAULT_MAPPER_TYPE);
        }

        public ServeyMethodModel getServeyById(string serveyId)
        {
            try
            {
                _ServeyMethodDAO = CreateSQLDAO();

                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {ServeyMethodModel.FIELD_SURVEY_METHOD_ID,FIELD_SURVEY_METHOD_ID},
                    {ServeyMethodModel.FIELD_NAME,FIELD_NAME},
                    {ServeyMethodModel.FIELD_CODE,FIELD_CODE},  
                    {ServeyMethodModel.FIELD_DESCRIPTIONS,FIELD_DESCRIPTIONS}
                    
                };

                return _ServeyMethodDAO.GetById(serveyId, mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public bool createOrUpdateServey(ServeyMethodModel serveyMethodModel)
        {
            try
            {
                _ServeyMethodDAO = CreateSQLDAO();
                return _ServeyMethodDAO.createOrUpdateServey(serveyMethodModel);
            }
            catch (Exception e)
            {
                return false;
            }           
        }

        public bool deleteServey(string[] serveyId)
        {
            try
            {
                _ServeyMethodDAO = CreateSQLDAO();
                return _ServeyMethodDAO.deleteServey(serveyId);
            }
            catch (Exception e)
            {
                return false;
            }
        }

        public bool checkSurveyExist(string serveyId, string Code, string Name)
        {
            try
            {
                _ServeyMethodDAO = CreateSQLDAO();
                return _ServeyMethodDAO.checkSurveyExist(serveyId, Code, Name);
            }
            catch (Exception e)
            {
                return false;
            }
        }
    }
}
